package com.example.yk_lx.baseMVVM;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.jaeger.library.StatusBarUtil;

public abstract class BaseFragment<VDB extends ViewDataBinding,VM extends BaseViewModel> extends Fragment {
    protected VDB dataBinding;
    protected VM viewModel;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.inflate(inflater,bindLayout(),container,false);
        viewModel = new ViewModelProvider(this).get(getViewModel());
        initView();
        initData();
        //沉浸式状态栏
        StatusBarUtil.setTranslucentForImageView(getActivity(),0,null);
        return dataBinding.getRoot();
    }


    protected abstract int bindLayout();
    protected abstract void initView();
    protected abstract void initData();
    protected abstract Class<VM> getViewModel();
}
